home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* */
- /* Application: icl8 To cicn */
- /* */
- /* Description: This snippet converts a 'icl8' and 'ICN#' resource */
- /* to a 'cicn' resource. */
- /* */
- /* Files: icl8 To cicn.π */
- /* icl8 To cicn.c */
- /* icl8 To cicn.π.rsrc */
- /* */
- /* Programmer: Edgar Lee */
- /* Organization: Apple Computer, Inc. */
- /* Department: Developer Technical Support, DTS */
- /* Language: C (Think C version 5.0.2) */
- /* Date Created: 12-29-92 */
- /* */
- /****************************************************************************/
-
- #include <Dialogs.h>
- #include <Fonts.h>
- #include <Resources.h>
- #include <Icons.h>
-
- /* Constant Declarations */
-
- #define WWIDTH 320
- #define WHEIGHT 320
-
- #define WLEFT (((qd.screenBits.bounds.right - qd.screenBits.bounds.left) - WWIDTH) / 2)
- #define WTOP (((qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) - WHEIGHT) / 2)
-
- /* Global Variable Definitions */
-
- WindowPtr gWindow;
- CIconHandle gCICN;
-
- void initMac();
- void createWindow();
- void doEventLoop();
-
- void icl8ToCICN();
- void drawIcon();
-
- void main(void)
- {
- initMac();
-
- createWindow();
- icl8ToCICN();
-
- doEventLoop();
- }
-
- void initMac()
- {
- MaxApplZone();
-
- InitGraf( &qd.thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( nil );
- InitCursor();
- FlushEvents( 0, everyEvent );
- }
-
- void createWindow()
- {
- Rect rect;
-
- SetRect( &rect, WLEFT, WTOP, WLEFT + WWIDTH, WTOP + WHEIGHT );
-
- gWindow = NewCWindow( 0L, &rect, "\p'icl8' To 'cicn'", true, noGrowDocProc,
- (WindowPtr)-1L, true, 0L );
- SetPort( gWindow );
- }
-
- void icl8ToCICN()
- {
- Handle icn; /* Handle to the icon's bitmap image and mask. */
- Handle icl8; /* Handle to the icl8 resource. */
- char depth; /* Depth of the icl8 pixel image. */
- Rect bounds; /* Bounding rect for the icon. */
- long bitmapSize; /* Size of the icon's bitmap. */
-
- SetRect( &bounds, 0, 0, 32, 32 ); /* 'icl8' are 32x32 pixels. */
- depth = 8; /* 8-bit deep pixel image. */
- bitmapSize = 4 * 32; /* 4 bytesPerRow * 32 rows. */
-
- /* Load and lock the 'icl8' and 'ICN#' resources used to build the 'cicn'. */
-
- icn = GetResource( 'ICN#', 128 );
- icl8 = GetResource( 'icl8', 128 );
-
- HLock( icn );
- HNoPurge( icn );
-
- HLock( icl8 );
- HNoPurge( icl8 );
-
- /* Allocate memory for the 'cicn'. */
-
- gCICN = (CIconHandle)NewHandleClear( (long)sizeof( CIcon ) );
-
- /* Fill in the cicn's bitmap fields. */
-
- (**gCICN).iconBMap.baseAddr = nil;
- (**gCICN).iconBMap.rowBytes = 4;
- (**gCICN).iconBMap.bounds = bounds;
-
- /* Fill in the cicn's mask bitmap fields. */
-
- (**gCICN).iconMask.baseAddr = nil;
- (**gCICN).iconMask.rowBytes = 4;
- (**gCICN).iconMask.bounds = bounds;
-
- /* Fill in the cicn's pixmap fields. */
-
- (**gCICN).iconPMap.baseAddr = nil;
- (**gCICN).iconPMap.rowBytes = (((bounds.right - bounds.left) * depth) / 8) | 0x8000;
- (**gCICN).iconPMap.bounds = bounds;
- (**gCICN).iconPMap.pmVersion = 0;
- (**gCICN).iconPMap.packType = 0;
- (**gCICN).iconPMap.packSize = 0;
- (**gCICN).iconPMap.hRes = 72;
- (**gCICN).iconPMap.vRes = 72;
- (**gCICN).iconPMap.pixelSize = depth;
- (**gCICN).iconPMap.planeBytes = 0;
- (**gCICN).iconPMap.pmReserved = 0;
- (**gCICN).iconPMap.pixelType = 0;
- (**gCICN).iconPMap.cmpCount = 1;
- (**gCICN).iconPMap.cmpSize = depth;
- (**gCICN).iconPMap.pmTable = GetCTable( depth );
-
- /* Set the 'icl8' pixel image to the iconData field. */
-
- (**gCICN).iconData = (Handle)icl8;
-
- /* Resize the 'cicn' for the bitmap image and mask. */
-
- SetHandleSize( (Handle)gCICN, sizeof( CIcon ) + (bitmapSize * 2) );
-
- /* Copy the 'ICN#' data into the iconMaskData array. */
- /* Note1: This is an array of shorts, so divide bitmapSize by 2. */
- /* Note2: The mask comes before the image. The is opposite of an 'ICN#' */
-
- BlockMove( *icn, &(**gCICN).iconMaskData[bitmapSize / 2], bitmapSize ); /* The 1bit image. */
- BlockMove( *icn + (long)bitmapSize, (**gCICN).iconMaskData, bitmapSize ); /* The mask. */
- }
-
- void drawIcon()
- {
- /* Paint the background red to see that the icon's mask does work. */
-
- ForeColor( redColor );
- PaintRect( &(*gWindow).portRect );
-
- /* Now, draw the 'cicn' */
-
- PlotCIcon( &(*gWindow).portRect, gCICN );
- }
-
- void doEventLoop()
- {
- EventRecord event;
- WindowPtr window;
- short clickArea;
- Rect screenRect;
-
- for (;;)
- {
- if (WaitNextEvent( everyEvent, &event, 0, nil ))
- {
- if (event.what == mouseDown)
- {
- clickArea = FindWindow( event.where, &window );
-
- if (clickArea == inDrag)
- {
- screenRect = (**GetGrayRgn()).rgnBBox;
- DragWindow( window, event.where, &screenRect );
- }
- else if (clickArea == inContent)
- {
- if (window != FrontWindow())
- SelectWindow( window );
- }
- else if (clickArea == inGoAway)
- if (TrackGoAway( window, event.where ))
- return;
- }
- else if (event.what == updateEvt)
- {
- window = (WindowPtr)event.message;
- SetPort( window );
-
- BeginUpdate( window );
- drawIcon();
- EndUpdate( window );
- }
- }
- }
- }